﻿// Write a program that reads a text file and inserts line numbers in front of each of its lines. 
// The result should be written to another text file.

using System;
using System.IO;

class NumerateTextFileLines
{
    static void Main()
    {
        try
        {
            string path = "../../";
            string fileNameWithExt = "NumerateTextFileLines.cs";
            string fileName = Path.GetFileNameWithoutExtension(fileNameWithExt);
            string inputFile = Path.Combine(path, fileNameWithExt);
            string outputFile = Path.Combine(path, fileName + "WithLines" + Path.GetExtension(fileNameWithExt));
            using (StreamReader reader = new StreamReader(inputFile))
            {
                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    int lineNumber = 1;
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        line = reader.ReadLine();
                        writer.WriteLine("{0}. {1}", lineNumber, line);
                        lineNumber++;
                    }
                }
            }

            Console.WriteLine("Lines number is activated in file: {0}", outputFile);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
}